package Files;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class File_ extends base{
	public File_() {}
	
	public boolean openFile(int value) {
			File f = new File(PathToFile(value));
			return f.exists();
	}
	public String getbasedirectory(){
		return MAINDIRECTORY+"\\";
	}
	public boolean isbasedirectory(){
		File f=new File(MAINDIRECTORY);
		return (f.exists())?true:createbasedirectory(); 
	}
	boolean createbasedirectory(){
		new File(MAINDIRECTORY).mkdir();
		return isbasedirectory();
	}
	public List<String> read__(String na){
		List<String> bb=new ArrayList<String>();
		BufferedReader br = null;
		 boolean opcje=false,ok=false,konieclinii=false,parametr=false;;
		try {
			
			String sCurrentLine;
 
			br = new BufferedReader(new FileReader("C:\\"+na+".txt"));
			StringBuffer aa=new StringBuffer("");
			while ((sCurrentLine = br.readLine()) != null) {
				parametr=true;
				//System.out.println(sCurrentLine);
				if(sCurrentLine.indexOf("options:")!=-1){
					opcje=true;continue;
				}
				if(opcje){
				char[] tab1=new char[sCurrentLine.length()];
				tab1=sCurrentLine.toCharArray();
				String aaa="";
				for (int i = 0; i < tab1.length; i++) {
					//System.out.print(tab1[i]);
					if ( tab1[i]=='D') {
						aaa+=tab1[i];
						if ( aaa.length()==7 && aaa.indexOf("Default")!=-1)
							System.out.println("DD");
					}
					if ( tab1[i]=='-' && parametr) {
						ok=true;
						continue;
					}
						
					if(ok){
						if(tab1[i]==' ') { 
							ok=false;parametr=false;
							bb.add(aa.toString());aa.delete(0, aa.length());
							continue; }
						else
						{
							aa.append(tab1[i]);
						}
					}
					else
						continue;
					}
				}
			//	System.out.println();
			//	System.out.println(bb);
			}
		//	System.out.println("FINISH "+ bb);
			return bb;
 
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		} finally {
			try {
				if (br != null)br.close();
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}
	}

	void saveToFile(int value) {
		try {
			FileOutputStream fout = null;
			fout = new FileOutputStream(PathToFile(value));
			ObjectOutputStream oos = new ObjectOutputStream(fout);
			oos.writeObject(mapa_);
			oos.close();
			saveToCommonStructure(value);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		
	}
	void saveToCommonStructure(int value){
		switch(value){
		case 0:
			common_map_commands=mapa_;break;
		case 1:
			common_map_labs=mapa_;break;
		}
	}

	/**
	 * 
	 * 
	 * @param a
	 * @param b
	 * @param value
	 *            (0-commands,1-labs)
	 */
	public void addToMap(String a, String b, int value) {
		if (openFile(value)) {
			readFile(value);
		}
		mapa_.put(b, b);
		address.setMapa(mapa_);
		saveToFile(value);
	}
	public void addToMapLab(String a, String b, int value) {
		if (openFile(value)) {
			readFile(value);
		}
		mapa_.put(a, b);
		//address.setMapa(mapa_);
		saveToFile(value);
	}

	public Map<String, String> getValues() {
		return address.getMapa();
	}
	public Map<String,String> readF(int value){
		readFile(value);
		return mapa_;
	}
	public static void onlyReadFile(int value){
		File_ onlyduringstartGUI= new File_();
		onlyduringstartGUI.ff(value);
	}
	public void ff(int value){
		readFile(value);
		
	}
	  void readFile(int value) {
		try {
			if(openFile(value)){
			FileInputStream fin = null;
			fin = new FileInputStream(PathToFile(value));
			ObjectInputStream ois = new ObjectInputStream(fin);
			mapa_=(Map<String,String>)ois.readObject();
			ois.close();
			saveToCommonStructure(value);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	@Override
	void method1() {
		// TODO Auto-generated method stub
		
	}
	String a="";
	
	   public class htmlparse{
		   Map<String,Set<String>> aa=new HashMap<String,Set<String>>();
		   List<String> cc=new ArrayList<String>();
/*		   {
			   cc.add("3GPP_Upload");cc.add("3GPP_Download");cc.add("Restore_Configuration");
			   cc.add("Restore_FlexiBTS_Configuration");
			   cc.add("Compare");
			   cc.add("Policy_Based_Compare");
			   cc.add("Actual_Check");
			   cc.add("Plan_Check");
			   cc.add("Reference");
cc.add("Check");
cc.add("planDeletion");
			   								cc.add("Import_Export");
			   										cc.add("Upload");
			   												cc.add("Provision");
			   														cc.add("Validate");
			   																cc.add("Activate_Pre-Activation");
			   																		cc.add("IPA_Validation");
			   																				cc.add("IPA_Activation");
			   																						cc.add("Init_Reference_Conf");
			   																								cc.add("Delta_Generation");
			   																										cc.add("Merge_Plan");
cc.add("Commit_Align_Network");
		cc.add("Calibrate");
				cc.add("Binary_Download");
						cc.add("Send_To_Network");
								cc.add("eNB_Automated_Site_Plan_Preparation");
										cc.add("BTS_Automated_Site_Plan_Preparation");
												cc.add("MMLCommandExecution");
														cc.add("BTS_SEM_Export");
																cc.add("Init_History");
																		cc.add("Synchronize_History");
																				cc.add("Diff_History");
																						cc.add("Admin_Manage_Queue");
																								cc.add("Broadcast_Generate_MML");
																										cc.add("Broadcast_Plan_Actual_Comparison");
																												cc.add("Broadcast_Provision_Plan");
			   
		   }*/
		  public htmlparse(){
			 a="a";
			try{
			File file=new File("C:/CLI_Operations_NETACT_8.htm");
			FileReader fr=new FileReader(file);
			BufferedReader br=new BufferedReader(fr);
			StringBuffer sb=new StringBuffer();
			String line;
			
			while((line=br.readLine())!=null){
				if (line.indexOf("title heading topictitle1")!=-1)
					
				sb.append(line);sb.append("\n");
				
			}
			fr.close();
			System.out.println(sb.toString());
			}
			catch(Exception ee){}
			
		}
	}
	public static Map<String,String> 
		common_map_commands,
		common_map_labs=new HashMap<String, String>();
}
